﻿using com.ruovea.utilty;
using com.ruovea.utilty.rstring;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GogsWeb.Api.Builde
{
    /// <summary>
    /// 
    /// </summary>
    public class BuildeIndex
    {
        /// <summary>
        /// 初始化
        /// </summary>
       public static void Init()
        {
            SqlSugar.SqlSugarClient sc = new SqlSugar.SqlSugarClient(new SqlSugar.ConnectionConfig { ConnectionString = "Data Source=gogs.db", DbType = SqlSugar.DbType.Sqlite });
            var list = sc.DbMaintenance.GetTableInfoList();
            foreach (var t in list)
            {
                string modeName = Str.ToCamelAny(t.Name);
                string bodyStr = body(modeName);
                com.ruovea.vfile.FileHelper.CreateFile($"BuildeFile/Controllers/{modeName}Controller.cs", bodyStr.GetBytes());
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="modeName"></param>
        /// <returns></returns>
        public static string body(string modeName)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("using com.ruovea.gogs.entity;\n");
            sb.Append("namespace GogsWeb.Api.Controllers\n");
            sb.Append("{\n");
            sb.Append("    /// <summary>\n");
            sb.Append($"    /// {modeName}\n");
            sb.Append("    /// </summary>\n");
            sb.Append($"    public class {modeName}Controller : BaseController<{modeName}Entity>\n");
            sb.Append("    {\n");
            sb.Append("\n");
            sb.Append("    }\n");
            sb.Append("}\n");
            return sb.ToString();
        }
    }
}
